#include "StompedReality/Core/Input/Windows/WGLKeyboardHandler.h"
#include <assert.h>
#include <iostream>
namespace StompedReality
{
namespace Input
{
WGLKeyboardHandler::WGLKeyboardHandler( )
  : KeyboardHandler( )
{
  this->m_Keys = new bool[300];

  //UpdateKeys = 0;
  for ( int i = 0; i < 300; ++i )
  {
    this->m_Keys[i] = 0; //KeyEventType::NONE;
  }
}

WGLKeyboardHandler::~WGLKeyboardHandler( )
{
  delete[] this->m_Keys;
}

void WGLKeyboardHandler::Intialize( )
{
}

void WGLKeyboardHandler::UpdateKeys( )
{
  if (!this->m_DownSet.empty( ) || !this->m_UpSet.empty( )) {
    for (int i = 0; i< 300; i++) {
      if (this->m_DownSet.find( i ) != this->m_DownSet.end( ) &&
          this->m_UpSet.find( i ) != this->m_UpSet.end( ) ) {
        this->m_Keys[i] = 1;
      }
      else {
        this->m_Keys[i] = 0;
      }
    }
    this->m_UpSet.clear( );
    this->m_DownSet.clear( );
  }
  this->m_Keyboard->UpdateKeys ( this->m_Keys );
}

void WGLKeyboardHandler::ProcessMessage( StompedReality::Core::SystemMessage* msg )
{
  assert( msg != 0 );
  switch ( msg->message  )
  {
  case WM_KEYDOWN:
    this->m_DownSet.insert( msg->wParam );
  case WM_KEYUP:
    this->m_UpSet.insert( msg->wParam );
  }
}

}
}
